const Mock = require('mockjs')

// 生成APP用户统计数据
function generateAppUserStats() {
  const apps = [
    { name: '星球客', code: 'xqk', color: '#409EFF' },
    { name: '有球体育', code: 'yqty', color: '#67C23A' },
    { name: '310大师', code: '310', color: '#E6A23C' }
  ]
  
  const stats = apps.map(app => ({
    appName: app.name,
    appCode: app.code,
    userCount: Mock.Random.integer(5000, 50000),
    color: app.color,
    growth: Mock.Random.float(5, 25, 1, 1)
  }))
  
  return stats
}

// 生成用户增长趋势数据
function generateUserGrowthTrend(days = 30) {
  const dates = []
  const xqkData = []
  const yqtyData = []
  const android310Data = []
  const ios310Data = []
  
  const today = new Date()
  
  for (let i = days - 1; i >= 0; i--) {
    const date = new Date(today)
    date.setDate(date.getDate() - i)
    dates.push(date.toISOString().split('T')[0])
    
    // 生成带有趋势的随机数据
    const baseXqk = 200 + (days - i) * 2
    const baseYqty = 150 + (days - i) * 1.5
    const baseAndroid310 = 100 + (days - i) * 1
    const baseIos310 = 80 + (days - i) * 0.8
    
    xqkData.push(baseXqk + Mock.Random.integer(-50, 100))
    yqtyData.push(baseYqty + Mock.Random.integer(-30, 80))
    android310Data.push(baseAndroid310 + Mock.Random.integer(-20, 60))
    ios310Data.push(baseIos310 + Mock.Random.integer(-15, 50))
  }
  
  return {
    dates,
    series: [
      { name: '星球客', data: xqkData, color: '#409EFF' },
      { name: '有球体育', data: yqtyData, color: '#67C23A' },
      { name: '310大师安卓', data: android310Data, color: '#E6A23C' },
      { name: '310大师苹果', data: ios310Data, color: '#F56C6C' }
    ]
  }
}

module.exports = [
  // 获取用户统计数据
  {
    url: '/api/user/stats',
    type: 'get',
    response: () => {
      const totalUsers = Mock.Random.integer(100000, 200000)
      const newUsers = Mock.Random.integer(500, 2000)
      const activeUsers = Mock.Random.integer(10000, 30000)
      
      return {
        code: 200,
        message: 'success',
        data: {
          totalUsers,
          newUsers,
          activeUsers,
          growth: Mock.Random.float(5, 25, 1, 1)
        }
      }
    }
  },

  // 获取各APP用户数量统计
  {
    url: '/api/user/app-stats',
    type: 'get',
    response: () => {
      const appStats = generateAppUserStats()
      return {
        code: 200,
        message: 'success',
        data: appStats
      }
    }
  },

  // 获取用户增长趋势
  {
    url: '/api/user/growth-trend',
    type: 'get',
    response: (config) => {
      const { days = 30 } = config.query
      const trendData = generateUserGrowthTrend(parseInt(days))
      return {
        code: 200,
        message: 'success',
        data: trendData
      }
    }
  }
]
